<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>小说封面图片上传</title>
	<link rel="stylesheet" href="layui/css/layui.css">
</head>

<body class="layui-bg-gray">
	<!--顶部导航栏-->
    <%@ include file="novelhead.jsp" %>
    
	<!--小说相关信息编辑-->
	<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 50px;">
		<!--小说信息-->
		<div class="layui-card">
			<div class="layui-card-body">
			<form class="layui-form layui-form-pane" action="
			getuploadpictures.action?userid=${loginuser.userid }&novelid=${novel.novelid}" method='post'>
				<table class="layui-table" style="text-align: center">
					<tr>
						<td class="layui-bg-blue">
							<h3><b>请选择一张小说的封面图片</b></h3>
							<div display="none">
								<input id="userimg" value="${loginuser.userid }" style="display:none">
								<input id="novelimg" value="${novel.novelid}" style="display:none">
								<input id="photoname" name="photoname" value="" style="display:none">
							</div>
						</td>
					</tr>
					<tr>
						<td style="height: 250px">
							<div class="layui-upload">
								<div class="layui-upload-list" style="text-align: center">
									<img src="img/defaultuser.jpg" class="layui-upload-img" id="upimg" />
									<h3><b>${novel.novelname }</b></h3>
									<button type="button" name="btnaddphoto" class="layui-btn layui-btn-normal" id="uptest"
										style="margin-top:25px">上传小说封面</button>
								</div>
							</div>
						</td>
					</tr>
				</table>
				<div class="layui-form-item" style="text-align: center">
                     <button class="layui-btn" lay-submit lay-filter="formDemo">+创建小说</button>
                </div>
			</form>
			</div>
		</div>
		<%@ include file="foot.jsp" %>
		
		<script src="layui/layui.js" charset="utf-8"></script>
		<script>
			//图片上传
   	layui.use('upload', function() {
        var $ = layui.jquery,
            upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uptest',
            url:'fileupload.do?path=' +$("#userimg").val() +'//'+$("#novelimg").val(),
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result) {
                    $('#upimg').attr('src', result); //图片链接（base64）
                });
               
            },
            done: function(res) {
				$('#photoname').val(res.result1);
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function() {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</ a>');
                demoText.find('.demo-reload').on('click', function() {
                    uploadInst.upload();
                });
            }
        });
    });
		</script>
</body>

</html>